#define _CRT_SECURE_NO_WARNINGS 1

bool flag;
PreOrderCompare(struct TreeNode* root, int val)
{
    if (root == NULL || flag == false)
    {
        return;
    }

    if (root->val != val)
    {
        flag = false;
    }

    PreOrderCompare(root->left, val);
    PreOrderCompare(root->right, val);
}

bool isUnivalTree(struct TreeNode* root) {
    if (root == NULL)
        return true;
    flag = true;
    PreOrderCompare(root, root->val);
    return flag;
}